package com.sunday.msq.activity;

import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.view.animation.TranslateAnimation;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sunday.frame.BaseActivity;
import com.sunday.frame.LayoutInject;
import com.sunday.frame.ViewInject;
import com.sunday.msq.R;

/**
 * 引导页面
 * @author 晨曦
 *
 */

@LayoutInject(R.layout.splash_layout)
public class SplashActivity extends BaseActivity implements OnClickListener{

	@ViewInject(value=R.id.back_ll,onclick=false)
	private LinearLayout background;
	@ViewInject(value=R.id.menu,onclick=false)
	private LinearLayout menu;
	@ViewInject(value=R.id.login,onclick=true)
	private TextView login;
	@ViewInject(value=R.id.register,onclick=true)
	private TextView register;
	
	
	@Override
	protected void createActivity() {
		// TODO Auto-generated method stub
		
		Animation anim=AnimationUtils.loadAnimation(this, R.anim.alpha);
		anim.setAnimationListener(new AnimationListener() {
			
			@Override
			public void onAnimationStart(Animation animation) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onAnimationRepeat(Animation animation) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onAnimationEnd(Animation animation) {
				// TODO Auto-generated method stub
				//设置切换动画，从右边进入，左边退出
				//已登录，直接进主界面，否则显示登录菜单
				if(false){
					overridePendingTransition(R.anim.in_from_right, R.anim.out_to_left);	
					Intent in=new Intent(mActivity, HomeActivity.class);
					startActivity(in);
				}else{
					menu.setVisibility(View.VISIBLE);
					Animation anim = new TranslateAnimation(0,
							0, SplashActivity.this.getWindowManager().getDefaultDisplay().getHeight(), 0);
					anim.setDuration(1500);
					menu.startAnimation(anim);
				}
			}
		});
		background.startAnimation(anim);
		
	}


	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch(v.getId()){
		case R.id.login:
			Intent in=new Intent(mActivity, LoginActivity.class);
			startActivity(in);
			break;
		case R.id.register:
			Intent in2=new Intent(mActivity, RegisterActivity.class);
			startActivity(in2);
			break;
		}
	}
	
}



